package
{
	public class TestPoint_Tile
	{
		private static var Test_PointTile:Object;

		public static function initialize():void
		{
			TestPoint_Tile.Test_PointTile = new Object();
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_FULL] = TestPoint_Tile.TestPoint_Full;
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_45DEG] = TestPoint_Tile.TestPoint_45Deg;
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_CONCAVE] = TestPoint_Tile.TestPoint_Concave;
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_CONVEX] = TestPoint_Tile.TestPoint_Convex;
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_22DEGs] = TestPoint_Tile.TestPoint_22DegS;
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_22DEGb] = TestPoint_Tile.TestPoint_22DegB;
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_67DEGs] = TestPoint_Tile.TestPoint_67DegS;
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_67DEGb] = TestPoint_Tile.TestPoint_67DegB;
			TestPoint_Tile.Test_PointTile[TileMapCell.CTYPE_HALF] = TestPoint_Tile.TestPoint_Half;
		}

		//
		public static function QueryPointvsTileMap(x:Number, y:Number):Boolean
		{
			var tile:TileMapCell = Main.getInstance().tiles.GetTile_S(x, y);
			return TestPointTile(x, y, tile);
		}

		//
		private static function TestPointTile(x:Number, y:Number, t:TileMapCell):Boolean
		{
			if (t.ID > 0)
			{
				return Test_PointTile[t.CTYPE](x, y, t);
			}
			return false;
		}

		//
		private static function TestPoint_Full(x:Number, y:Number, tile:TileMapCell):Boolean
		{
			return true;
		}

		// 点乘法
		private static function TestPoint_45Deg(x:Number, y:Number, t:TileMapCell):Boolean
		{
			var ox:Number = x - t.pos.x;
			var oy:Number = y - t.pos.y;
			if (ox * t.sx + oy * t.sy <= 0)
			{
				return true;
			}
			return false;
		}

		// 半径法
		private static function TestPoint_Concave(x:Number, y:Number, t:TileMapCell):Boolean
		{
			var ox:Number = (t.pos.x + t.signx * t.xw) - x;
			var oy:Number = (t.pos.y + t.signy * t.yw) - y;
			var radius:Number = t.xw * 2;
			if (radius * radius <= ox * ox + oy * oy)
			{
				return true;
			}
			return false;
		}

		// 半径法
		private static function TestPoint_Convex(x:Number, y:Number, t:TileMapCell):Boolean
		{
			var ox:Number = x - (t.pos.x - t.signx * t.xw);
			var oy:Number = y - (t.pos.y - t.signy * t.yw);
			var radius:Number = t.xw * 2;
			if (ox * ox + oy * oy <= radius * radius)
			{
				return true;
			}
			return false;
		}

		// 点乘法
		private static function TestPoint_22DegS(x:Number, y:Number, t:TileMapCell):Boolean
		{
			var ox:Number = x - (t.pos.x + t.signx * t.xw);
			var oy:Number = y - (t.pos.y - t.signy * t.yw);
			if (ox * t.sx + oy * t.sy <= 0)
			{
				return true;
			}
			return false;
		}

		// 点乘法
		private static function TestPoint_22DegB(x:Number, y:Number, t:TileMapCell):Boolean
		{
			var ox:Number = x - (t.pos.x - t.signx * t.xw);
			var oy:Number = y - (t.pos.y + t.signy * t.yw);
			if (ox * t.sx + oy * t.sy <= 0)
			{
				return true;
			}
			return false;
		}

		// 点乘法
		private static function TestPoint_67DegS(x:Number, y:Number, t:TileMapCell):Boolean
		{
			var ox:Number = x - (t.pos.x - t.signx * t.xw);
			var oy:Number = y - (t.pos.y + t.signy * t.yw);
			if (ox * t.sx + oy * t.sy <= 0)
			{
				return true;
			}
			return false;
		}

		// 点乘法
		private static function TestPoint_67DegB(x:Number, y:Number, t:TileMapCell):Boolean
		{
			var ox:Number = x - (t.pos.x + (t.signx * t.xw));
			var oy:Number = y - (t.pos.y - (t.signy * t.yw));
			if (ox * t.sx + oy * t.sy <= 0)
			{
				return true;
			}
			return false;
		}

		// 点乘法
		private static function TestPoint_Half(x:Number, y:Number, tile:TileMapCell):Boolean
		{
			var ox:Number = x - tile.pos.x;
			var oy:Number = y - tile.pos.y;
			if (ox * tile.signx + oy * tile.signy <= 0)
			{
				return true;
			}
			return false;
		}
	}
}